package com.example.psychologicalappointmentsystem.Controller;

import com.example.psychologicalappointmentsystem.Object.ChatMessageVO;
import com.example.psychologicalappointmentsystem.service.ChatMessageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * ClassName ChatController
 * Description TODO 消息发送与接受
 * Date 2025/2/14 16:24
 * Version 1.0
 */
@Controller
@RequestMapping("/api/chat")
public class ChatController {

    @Autowired
    private ChatMessageService messageService;
    /*
     *
     *实现逻辑:
     *客户端收到消息后发送确认请求。
     *后端更新消息状态并通知发送方。
     * @author feller
     **/
    @RequestMapping(value = "/mark-as-read", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> markMessageAsRead(@RequestBody ChatMessageVO chatMessageVO) {
        messageService.updateMessageStatus(chatMessageVO);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("返回近7天的历史记录")
    @RequestMapping(value = "/chatHistory", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public ResponseEntity<?> chatHistory(@RequestBody ChatMessageVO chatMessageVO) {
        return messageService.chatHistory(chatMessageVO);
    }

    @ApiOperation("返回左侧聊天记录列表")
    @RequestMapping(value = "/session", method = RequestMethod.GET)
    public ResponseEntity<?> chatSession() {
        return messageService.chatSession();
    }

    @ApiOperation("获取未读消息小红点")
    @RequestMapping(value = "/unread", method = RequestMethod.GET)
    public ResponseEntity<?> unread() {
        return messageService.unread();
    }

}
